#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R x<<1|1
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define OK Ll<=l&&r<=Rr
#define Root 1,1,n
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
inline ll Read(){ll s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}

using namespace std;
const int N=1e5+5,M=1e7+5,inf=(1LL<<31)-1,mod=998244353;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int n,m,q,c[N],a[N][6];
struct mac{
	ll a[5][5];
	inline void clear(){
		rep(i,0,m-1)rep(j,0,m-1)a[i][j]=-llf;
	}
	mac friend operator*(mac a,mac b){
		mac c;
		c.clear();
		rep(i,0,m-1)rep(k,0,m-1)if(a.a[i][k])rep(j,0,m-1)c.a[i][j]=max(c.a[i][j],a.a[i][k]+b.a[k][j]);
		return c;
	}
}xd[N<<2],S[6];
inline void build(int x,int l,int r){
	if(l==r){
		xd[x].clear();
		rep(j,0,m-1)if(j!=c[l]-1)xd[x].a[j][j]=a[l][j+1];
		xd[x].a[c[l]-1][c[l]-1]=a[l][c[l]];
		if(l>1)xd[x].a[c[l]-1][c[l-1]-1]=a[l][c[l]];
		return;
	}
	build(lc),build(rc),xd[x]=xd[R]*xd[L];
}
inline void modify(int x,int l,int r,int p){
	if(p>r)return;
	if(l==r){
		xd[x].clear();
		rep(j,0,m-1)if(j!=c[l]-1)xd[x].a[j][j]=a[l][j+1];
		xd[x].a[c[l]-1][c[l]-1]=a[l][c[l]];
		if(l>1)xd[x].a[c[l]-1][c[l-1]-1]=a[l][c[l]];
		return;
	}
	p<=mid?modify(lc,p):modify(rc,p),xd[x]=xd[R]*xd[L];
}
inline mac query(int x,int l,int r,int Ll,int Rr){
	if(OK)return xd[x];
	if(Rr<=mid)return query(lc,Ll,Rr);
	if(Ll>mid)return query(rc,Ll,Rr);
	return query(rc,Ll,Rr)*query(lc,Ll,Rr);
}
ll lastans;
inline void Main(){
	n=read(),m=read(),q=read();
	repn(i)c[i]=read();
	repn(i)repm(j)a[i][j]=read();
	build(Root);
	repm(i)S[i].clear(),S[i].a[i-1][0]=0;
	ll lastans=0;
	cout <<(lastans=(xd[1]*S[c[1]]).a[c[n]-1][0])<<'\n';
	while(q--){
		int ty=read(),x=Read()^lastans,y=Read()^lastans;
		if(ty==1)c[x]=y,modify(Root,x),modify(Root,x+1);
		else cout <<(lastans=(query(Root,x,y)*S[c[x]]).a[c[y]-1][0])<<'\n';
	}
}
signed main(){
	freopen("paint.in","r",stdin);
	freopen("paint.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}